// cQPSelectDocumentLibrariesPage.cpp : implementation file
//

#include "stdafx.h"
#include "qpmig.h"
#include "cQPSelectDocumentLibrariesPage.h"
#include "helper.h"
#include "noteshelperfunctions.h"
extern CQPMigApp theApp;

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// cQPSelectDocumentLibrariesPage property page

IMPLEMENT_DYNCREATE(cQPSelectDocumentLibrariesPage, CPropertyPageEx)

cQPSelectDocumentLibrariesPage::cQPSelectDocumentLibrariesPage() : CPropertyPageEx(cQPSelectDocumentLibrariesPage::IDD,0, IDS_QPSELECTDOCITEMSHEADERTITLE, IDS_QPSELECTDOCITEMSHEADERSUBTITLE)
{
	//{{AFX_DATA_INIT(cQPSelectDocumentLibrariesPage)
	//}}AFX_DATA_INIT
	m_bBeenHere=FALSE;

}

cQPSelectDocumentLibrariesPage::~cQPSelectDocumentLibrariesPage()
{
}

void cQPSelectDocumentLibrariesPage::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(cQPSelectDocumentLibrariesPage)
	DDX_Control(pDX, IDC_LIST1, m_lbItems);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(cQPSelectDocumentLibrariesPage, CPropertyPageEx)
	//{{AFX_MSG_MAP(cQPSelectDocumentLibrariesPage)
		// NOTE: the ClassWizard will add message map macros here
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// cQPSelectDocumentLibrariesPage message handlers


LRESULT cQPSelectDocumentLibrariesPage::OnWizardNext() 
{
	UpdateData(TRUE);
	DWORD dwErrCode=0;
	CString cTemp;
	DBHANDLE hDB=theApp.stControl.pdb->db.GetDatabaseHandle(TRUE);
	for(int i=0;i<m_lbItems.GetCount();i++)
		{
			if(m_lbItems.GetSel(i))
				{
					cNotesFolderInfo *pFolderInfo=(cNotesFolderInfo *)m_lbItems.GetItemDataPtr(i);
					if(pFolderInfo)
						{
							pFolderInfo->b_Transfer=TRUE;
							pFolderInfo->m_wType=DOCFOLDER;
/*							theApp.stControl.cobjNotesFolders.Add(pFolderInfo);
							IXMLDOMElementPtr pLibraryNode=theApp.stControl.pXMLDoc->createElement(L"container");
							IXMLDOMElementPtr pNode=theApp.stControl.pXMLDoc->createElement(L"name");
							pNode->put_text(pFolderInfo->m_strFolderDisplayName.AllocSysString());
							pLibraryNode->appendChild(pNode);

							pNode=theApp.stControl.pXMLDoc->createElement(L"type");
							pNode->put_text(L"Library");
							pLibraryNode->appendChild(pNode);

							pNode=theApp.stControl.pXMLDoc->createElement(L"template");
							pNode->put_text(L"QPDocLib");
							pLibraryNode->appendChild(pNode);

							pNode=theApp.stControl.pXMLDoc->createElement(L"relativeitemXML");
							CString cTemp;
							cTemp.Format("\\%s\\items.xml",pFolderInfo->m_strFolderDisplayName);
							pNode->put_text(cTemp.AllocSysString());
							pLibraryNode->appendChild(pNode);
							
							if(ProcessFolder(pFolderInfo,hDB,&theApp.stControl.db))
								{
									theApp.stControl.pContainerNode->appendChild(pLibraryNode);
								}
*/

						}
				};
		}
	
	return CPropertyPageEx::OnWizardNext();
}

BOOL cQPSelectDocumentLibrariesPage::OnSetActive() 
{
	CPropertySheet* psheet = (CPropertySheet*) GetParent();   
	psheet->SetWizardButtons(PSWIZB_BACK | PSWIZB_NEXT);
	if(m_bBeenHere)
		{
			CPropertyPageEx::OnSetActive();
		}
	m_lbItems.ResetContent();

	m_bBeenHere=TRUE;
	for(int i=0;i<=theApp.stControl.pdb->cobjNotesFolders.GetUpperBound();i++)
		{
			cNotesFolderInfo *pFolderInfo=(cNotesFolderInfo *)theApp.stControl.pdb->cobjNotesFolders.GetAt(i);
			if(pFolderInfo)
				{
					if(pFolderInfo->m_wType==NODEFFOLDER || pFolderInfo->m_wType==DOCFOLDER)
						{
							int id=m_lbItems.AddString(pFolderInfo->m_strFolderDisplayName);
							if(LB_ERR!=id)
								{
									m_lbItems.SetItemDataPtr(id,pFolderInfo);
									if(pFolderInfo->m_wType==DOCFOLDER && pFolderInfo->b_Transfer)
										m_lbItems.SetSel(id);
								}
						}


				}
			
		}
	
	return CPropertyPageEx::OnSetActive();
}

